package com.ruoyi.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.upload-dir}")
    private String uploadDir;  // 读取配置文件中的文件上传目录

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将 URL 映射到文件系统中的 "uploads" 文件夹
        // 通过配置文件读取 upload-dir 路径
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:" + uploadDir + "/");
    }
}
